package com.sky.controller.admin;


import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Slf4j
@Api(tags = "菜品分类管理")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("/page")
    @ApiOperation("查询信息")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){
        log.info("传过来的数据为：{}", categoryPageQueryDTO);
        PageResult pageResult=categoryService.page(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    @PostMapping
    @ApiOperation("增加菜品分类")
    public Result addCategory(@RequestBody CategoryDTO categoryDTO){
        log.info("传过来分类信息:{}",categoryDTO);
        categoryService.addCategory(categoryDTO);
        return Result.success();
    }

    @PostMapping("status/{status}")
    public Result startOrStop(@PathVariable Integer status,Long id){
        log.info("status={},id={}",status,id);
        categoryService.changeStatus(status,id);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("根据type查询分类")
    public Result<List<Category>> getByTypeCategory(Integer type){
        log.info("传过来的type为：{}",type);
        List<Category> categorys=categoryService.getByTypeCategory(type);
        return Result.success(categorys);
    }

    @PutMapping
    @ApiOperation("修改分类信息")
    public Result changeCategory(@RequestBody CategoryDTO categoryDTO){
        log.info("传过来的Category为:{}",categoryDTO);
        categoryService.changeCategory(categoryDTO);
        return Result.success();
    }

    @DeleteMapping
    @ApiOperation("根据id删除分类信息")
    public Result deleteCategory(Integer id){
        log.info("传过来的id为{}",id);
        categoryService.deleteCategory(id);
        return Result.success();
    }

}
